package com.jkchen.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jkchen.dao.UserDao;
import com.jkchen.pojo.User;
import com.jkchen.pojo.query.UserQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service //交给spring管理
public class UserServiceImpl implements UserService{

    @Autowired
    UserDao userDao;
    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public PageInfo<User> findByName(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPageNum(),userQuery.getPageSize());
        return new PageInfo<User>(userDao.findByName(userQuery));
    }

    @Override
    public boolean deleUserById(int id) {
        Integer i = userDao.deleUserById(id);
        if(i != null && i>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean findUserByName(String name) {
        List<User> userByName = userDao.findUserByName(name);
        if(userByName.size()==0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public User findById(Integer id) {
        return userDao.findById(id);
    }

    @Override
    public boolean UpdateUserById(User user) {
        Integer integer = userDao.UpdateUserById(user);
        if(integer!=0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean insertUser(User user) {
        Integer integer = userDao.insertUser(user);
        if(integer!=0){
            return true;
        }else{
            return false;
        }
    }


}
